<template>
    <el-input  v-model="currentValue"  placeholder=""  class='myInput'  clearable size="small"  @keyup.enter.native="addItem" autofocus>  </el-input>
</template>
<script>
export default {
    props:["data","exkey"],
    data(){
        return{
            currentValue:"",
            pre:"",
            num:"",
            tableData:[]
        }
    },
    created(){
        this.pre=this.exkey["pre"]
        this.num=this.exkey["num"]
        let sef=this;
        this.$post("bygex","byg/funeral/getFuneralSfItem",{type:"warehouse"}).then(data=>{
            sef.tableData=[];
            for(let i=1;i<data.item.length;i++){
                sef.tableData.push(data.item[i])
            }
        })
    },
    methods:{
        addItem(){
             console.log("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
               
            let row=null;
            for(let i=0;i<this.tableData.length;i++){
                let sfe_ex12=this.tableData[i].sfe_ex12;
                if(sfe_ex12==this.currentValue){
                    row=this.tableData[i];
                }
            }
            console.log(row)
            if(row){
                let whc_wpid=row.whc_wpid;
                let row2=null;
                let index=-1;
                for(let i=0;i<this.data[this.pre].length;i++){
                    if(this.data[this.pre][i].whc_wpid==whc_wpid){
                        row2=this.data[this.pre][i];
                        index=i;
                    }
                }
                if(!row2){
                    this.$set(this.data[this.pre],this.data[this.pre].length,row);
                }else{
                    console.log(row2);

                    let num=Number(row2[this.num]);
                    console.log(num)
                    this.$set(this.data[this.pre][index],this.num,(num+1))
                }
            }else{
                this.$message.error('未找到该物品');
            }
            this.currentValue="";
               
            
        }
    }
}
</script>